package hlhj.fhp.checkpoint.http

import com.example.mymvp.okrx.OkKtUtils
import com.lzy.okgo.OkGo
import com.lzy.okgo.cache.CacheMode
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableResponse
import hlhj.fhp.checkpoint.MyApp
import hlhj.fhp.checkpoint.javaBean.*
import hlhj.fhp.checkpoint.utils.SPHelper
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import java.io.File
import java.net.URL

/**
 * Created by Never Fear   on 2018\11\13 0013.
Never More....
 */
object Apis {
    fun sendSms(phone:String): Observable<Response<SendSMSBean>>? {

        return OkGo.post<SendSMSBean>(Urls.sendSMS)
                .params("phone",phone)
                .converter(object :MyJsonConvert<SendSMSBean>(){})
                .adapt(ObservableResponse<SendSMSBean>())
                .subscribeOn(Schedulers.io())
    }

    fun login(phone:String,code:String,recommend:String,imei:String): Observable<Response<LoginBean>>? {
        val httpParams = HttpParams()
        httpParams.put("phone",phone)
        httpParams.put("code",code)
        httpParams.put("recommend",recommend)
        httpParams.put("imei",imei)

        return OkGo.post<LoginBean>(Urls.Login)
                .params(httpParams)
                .converter(object :MyJsonConvert<LoginBean>(){})
                .adapt(ObservableResponse<LoginBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 用户信息
     */
    fun getUserInfo(): Observable<Response<UserInfoBean>>? {
        return OkGo.get<UserInfoBean>(Urls.getUserInfo)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .cacheKey(Urls.getUserInfo)
                .converter(object :MyJsonConvert<UserInfoBean>(){})
                .adapt(ObservableResponse<UserInfoBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 获取轮播
     */
    fun getBanner(): Observable<Response<BannerBean>>? {
        return OkGo.get<BannerBean>(Urls.banner)
                .converter(object :MyJsonConvert<BannerBean>(){})
                .adapt(ObservableResponse<BannerBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 获取公告
     */
    fun getNotice(): Observable<Response<NoticeBean>>? {
         return OkGo.get<NoticeBean>(Urls.notice)
                .converter(object :MyJsonConvert<NoticeBean>(){})
                .adapt(ObservableResponse<NoticeBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 违章车辆
     */
    fun getCarPage(): Observable<Response<CarPageBean>>? {
       return OkGo.get<CarPageBean>(Urls.carpages)
                .converter(object :MyJsonConvert<CarPageBean>(){})
                .adapt(ObservableResponse<CarPageBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     *添加违章车辆
     */
    fun addCar(id:Int,plate_number:String,vin:String,engine_number:String,car_type:String,car_owner:String,owner_phone:String,plate_type:String,
               city:String,registno:String,city_id:String): Observable<Response<MyBaseBean>>? {
        return OkGo.post<MyBaseBean>(Urls.Add_Car)
                .params("cityid",id)
                .params("hphm",plate_number)
                .params("classno",vin)
                .params("engineno",engine_number)
                .params("registno",registno)
                .params("city_id",city_id)
                .params("car_type",car_type)
                .params("car_owner",car_owner)
                .params("owner_phone",owner_phone)
                .params("plate_type",plate_type)
                .params("city",city)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 获取所有车牌种类
     */
    fun getAllPlate(): Observable<Response<PlateBean>>? {
      return  OkGo.get<PlateBean>(Urls.getAllPlate)
                .converter(object :MyJsonConvert<PlateBean>(){})
                .adapt(ObservableResponse<PlateBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 添加年检
     */
    fun addYear(plate_number:String,vin:String,engine_number:String,examine_date:String,owner_name:String,original_price:String): Observable<Response<AddYearBean>>? {
      return  OkGo.post<AddYearBean>(Urls.addYear)
              .params("plate_number",plate_number)
              .params("vin",vin)
              .params("engine_number",engine_number)
              .params("examine_date",examine_date)
              .params("owner_name",owner_name)
              .params("original_price",original_price)
                .converter(object :MyJsonConvert<AddYearBean>(){})
                .adapt(ObservableResponse<AddYearBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 添加反馈
     */
    fun addReport(advice:String): Observable<Response<MyBaseBean>>? {
      return  OkGo.post<MyBaseBean>(Urls.addReport)
               .params("advice",advice)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }

    /**
     * 信息查询
     */
    fun checkInfo(): Observable<Response<CheckInfoBean>>? {
       return OkGo.get<CheckInfoBean>(Urls.checkInfo)
                .converter(object :MyJsonConvert<CheckInfoBean>(){})
                .adapt(ObservableResponse<CheckInfoBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 公告详情
     */
    fun getNoticeDetail(id:Int): Observable<Response<NoticeDetailBean>>? {
        return OkGo.get<NoticeDetailBean>(Urls.noticeDetail)
                .params("id",id)
                .converter(object :MyJsonConvert<NoticeDetailBean>(){})
                .adapt(ObservableResponse<NoticeDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    /**
     * 获得联系方式
     */

    fun getContact(): Observable<Response<ServentBean>>? {
        return OkGo.get<ServentBean>(Urls.servent)
                .converter(object :MyJsonConvert<ServentBean>(){})
                .adapt(ObservableResponse<ServentBean>())
                .subscribeOn(Schedulers.io())
    }
    //详情
    fun getCostDetail(id:Int,page:Int): Observable<Response<CostBean>>? {
        return OkGo.get<CostBean>(Urls.costDetail)
                .params("id",id)
                .params("page",page)
                .converter(object :MyJsonConvert<CostBean>(){})
                .adapt(ObservableResponse<CostBean>())
                .subscribeOn(Schedulers.io())
    }
    //上传
    fun upLoad(source:File): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.upLoad)
                .params("source",source)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //实名认证
    fun indentify(name:String,idcard_hold_img:String,idcard_front_img:String,idcard_opposite_img:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.indentify)
//                .params("name",name)
                .params("idcard_hold_img",idcard_hold_img)
                .params("idcard_front_img",idcard_front_img)
                .params("idcard_opposite_img",idcard_opposite_img)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除车
    fun deleteCar(id:Int): Observable<Response<MyBaseBean>>? {
       return OkGo.get<MyBaseBean>(Urls.deleteCar)
                .params("id",id)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取城市
    fun getCity(): Observable<Response<LocationBean>>? {
        return OkGo.get<LocationBean>(Urls.getCity)
                .converter(object :MyJsonConvert<LocationBean>(){})
                .adapt(ObservableResponse<LocationBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取限制
    fun getLimit(city_prefix:String,plate_prefix:String): Observable<Response<LimitBean>>? {
       return OkGo.post<LimitBean>(Urls.getLimit)
                .params("city_prefix",city_prefix)
                .params("plate_prefix",plate_prefix)
                .converter(object :MyJsonConvert<LimitBean>(){})
                .adapt(ObservableResponse<LimitBean>())
                .subscribeOn(Schedulers.io())
    }
    //更新信息
    fun updateUser(nickname:String?,head_img:String?): Observable<Response<MyBaseBean>>? {
        val postRequest = OkGo.post<MyBaseBean>(Urls.updateUserInfo)
        nickname?.let {
            postRequest.params("nickname",it)
        }
        head_img?.let {
            postRequest.params("head_img",it)
        }
        return postRequest
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }

    //免责声明
    fun statement(): Observable<Response<StatementBean>>? {
        return OkGo.get<StatementBean>(Urls.statement)
                .converter(object :MyJsonConvert<StatementBean>(){})
                .adapt(ObservableResponse<StatementBean>())
                .subscribeOn(Schedulers.io())
    }
    //零钱
    fun getMoney(page:Int): Observable<Response<MoneyBean>>? {
        return OkGo.get<MoneyBean>(Urls.moeny)
                .params("page",page)
                .converter(object :MyJsonConvert<MoneyBean>(){})
                .adapt(ObservableResponse<MoneyBean>())
                .subscribeOn(Schedulers.io())
    }
    //提现
    fun getCash(account_type:Int,price:String,account:String): Observable<Response<MyBaseBean>>? {
        return OkGo.post<MyBaseBean>(Urls.getCash)
                .params("account_type",account_type)
                .params("price",price)
                .params("account",account)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //分享列表
    fun getShare(type:Int,page: Int,level:Int): Observable<Response<ShareBean>>? {
       return OkGo.get<ShareBean>(Urls.myShare)
               .params("level",level)
                .params("type",type)
                .params("page",page)
                .converter(object :MyJsonConvert<ShareBean>(){})
                .adapt(ObservableResponse<ShareBean>())
                .subscribeOn(Schedulers.io())
    }
    //常见问题
    fun getProblems(page:Int): Observable<Response<ProblemBean>>? {
       return OkGo.get<ProblemBean>(Urls.problem)
               .params("page",page)
               .converter(object :MyJsonConvert<ProblemBean>(){})
                .adapt(ObservableResponse<ProblemBean>())
                .subscribeOn(Schedulers.io())
    }
    //反馈中心
    fun getMyReport(status:Int,page:Int): Observable<Response<ReportCenterBean>>? {
      return  OkGo.get<ReportCenterBean>(Urls.myReport)
                .params("status",status)
                .params("page",page)
                .converter(object :MyJsonConvert<ReportCenterBean>(){})
                .adapt(ObservableResponse<ReportCenterBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取违章订单
    fun getViolationOrder(status: Int,page:Int): Observable<Response<ViolationOrderBean>>? {
       return OkGo.get<ViolationOrderBean>(Urls.violationOrder)
                .params("status",status)
                .params("page",page)
                .converter(object :MyJsonConvert<ViolationOrderBean>(){})
                .adapt(ObservableResponse<ViolationOrderBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取年检订单
    fun getYearOrderLists(status: Int,page: Int): Observable<Response<YearOrderBean>>? {
        return OkGo.get<YearOrderBean>(Urls.yearOrder)
                .params("status",status)
                .params("page",page)
                .converter(object :MyJsonConvert<YearOrderBean>(){})
                .adapt(ObservableResponse<YearOrderBean>())
                .subscribeOn(Schedulers.io())
    }
    //年检详情
    fun getYearDetail(id:Int): Observable<Response<YearDetailBean>>? {
       return OkGo.get<YearDetailBean>(Urls.yearDetail)
                .params("id",id)
                .converter(object :MyJsonConvert<YearDetailBean>(){})
                .adapt(ObservableResponse<YearDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    //年检车牌
    fun getYearLimit(): Observable<Response<YearLimitBean>>? {
       return OkGo.get<YearLimitBean>(Urls.yearLimit)
                .converter(object :MyJsonConvert<YearLimitBean>(){})
                .adapt(ObservableResponse<YearLimitBean>())
                .subscribeOn(Schedulers.io())
    }
    //激活
    fun acitvePay(type:Int): Observable<Response<String>>? {
       return OkGo.get<String>(Urls.activePay)
                .params("type",type)
                .converter(object :MyJsonConvert<String>(){})
                .adapt(ObservableResponse<String>())
                .subscribeOn(Schedulers.io())
    }
    //年检支付
    fun yearPay(type:Int,id:String): Observable<Response<String>>? {
       return OkGo.post<String>(Urls.yearPay)
                .params("type",type)
                .params("id",id)
                .converter(object :MyJsonConvert<String>(){})
                .adapt(ObservableResponse<String>())
                .subscribeOn(Schedulers.io())
    }
    //违章支付
    fun violationPay(type:Int,id:String): Observable<Response<String>>? {
       return OkGo.post<String>(Urls.violation)
                .params("type",type)
                .params("id",id)
                .converter(object :MyJsonConvert<String>(){})
                .adapt(ObservableResponse<String>())
                .subscribeOn(Schedulers.io())
    }
    //我的VIP
    fun myVip(): Observable<Response<MyVipBean>>? {
      return  OkGo.get<MyVipBean>(Urls.myVIP)
                .converter(object :MyJsonConvert<MyVipBean>(){})
                .adapt(ObservableResponse<MyVipBean>())
                .subscribeOn(Schedulers.io())
    }
    //绑定VIP
    fun bindVIP(number:String): Observable<Response<MyBaseBean>>? {
       return OkGo.post<MyBaseBean>(Urls.bindVIP)
               .params("number",number)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
    //检查登录
    fun checkME(imei:String): Observable<Response<MEBean>>? {
        return OkGo.get<MEBean>(Urls.checkME)
                .params("imei",imei)
                .converter(object :MyJsonConvert<MEBean>(){})
                .adapt(ObservableResponse<MEBean>())
                .subscribeOn(Schedulers.io())
    }

    //退出登录
    fun loginOut(): Observable<Response<MyBaseBean>>? {
       return OkGo.get<MyBaseBean>(Urls.loginOut)
                .converter(object :MyJsonConvert<MyBaseBean>(){})
                .adapt(ObservableResponse<MyBaseBean>())
                .subscribeOn(Schedulers.io())
    }
}